import { Selector } from '@ngxs/store';
import { LogisticsState, LogisticsStateModel } from './logistics.state';

export class LogisticsSelector {
  @Selector([LogisticsState])
  static list({list}: LogisticsStateModel) {
    return list;
  }

  @Selector([LogisticsState])
  static bill({bill}: LogisticsStateModel) {
    return bill;
  }

  @Selector([LogisticsState])
  static billTotalPrice({bill}: LogisticsStateModel) {
    if (!bill || !bill.data || bill.data.length === 0) return 0;
    let totalPrice = 0;
    for (let datum of bill.data) {
      totalPrice += datum.count * datum.data.price;
    }
    return totalPrice;
  }
}
